package com.zbbt.sportslottery.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;

import com.umeng.message.PushAgent;
import com.zbbt.sportslottery.R;
import com.zbbt.sportslottery.app.Constant;
import com.zbbt.sportslottery.util.KeyUtil;
import com.zbbt.sportslottery.util.LogUtil;
import com.zbbt.sportslottery.util.UmengUtil;

public class BaseActivity extends ActionBarActivity {
	protected String TAG = getClass().getSimpleName();
	protected Context context;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		context = this;
		super.onCreate(savedInstanceState);
		PushAgent.getInstance(context).onAppStart();//友盟统计是否活跃 来执行推送
		LogUtil.printI("BaseActivity", TAG + "->onCreate");
	}

	@Override
	protected void onStart() {
		super.onStart();
		LogUtil.printI("BaseActivity", TAG + "->onStart");
	}

	@Override
	protected void onResume() {
		super.onResume();
		LogUtil.printI("BaseActivity", TAG + "->onResume");
		UmengUtil.onResume(context);
		if (!TAG.equals("MainActivity")) {
			UmengUtil.onPageStart(TAG);
		}
	}

	@Override
	protected void onPause() {
		super.onPause();
		LogUtil.printI("BaseActivity", TAG + "->onPause");
		UmengUtil.onPause(context);
		if (!TAG.equals("MainActivity")) {
			UmengUtil.onPageEnd(TAG);
		}
	}

	@Override
	protected void onStop() {
		super.onStop();
		LogUtil.printI("BaseActivity", TAG + "->onStop");
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		LogUtil.printI("BaseActivity", TAG + "->onDestroy");
	}

	/**
	 * Activity跳转
	 */
	public void goActivity(Class<?> clazz) {
		Intent intent = new Intent(context, clazz);
		startActivity(intent);
	}
	protected void goActivity2(Class<?> clazz,int gotoType,int gotonum ) {
		Intent intent = new Intent(context, clazz);
		intent.putExtra(KeyUtil.GotoType, gotoType);
		intent.putExtra(KeyUtil.FragmentKey, gotonum);
		startActivity(intent);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == Constant.FINISH_THIS_ACTIVITY && resultCode == RESULT_OK) {
			finishActivity();
		}
	}

	protected void finishActivity() {
		((Activity) context).setResult(RESULT_OK);
		finish();
	}

	protected void finishActivityAnimation() {
		finish();
		overridePendingTransition(R.anim.push_right_out, R.anim.push_right_in);
	}
}
